package edu.colorado.karl.intelsched;

/**
 *  RSSData is a container class that stores titles and descriptions for elements retrieved
 * from an RSS feed by the RSSReader.
 * @author Michael Knudson
 * @version 5/4/2007
 */
public class RSSData {
	private StringArray descs;
	private StringArray titles;
	
	/**
	 * Creates a new RSSData wrapper around the provided information.
	 * @param t	A list of RSS article titles.
	 * @param d A list of RSS article descriptions.
	 */
	public RSSData(StringArray t, StringArray d) {
		titles = t;
		descs = d;
		if(descs.size() != titles.size())
			throw new IllegalArgumentException("Size mismatch: " + d.size() + " != " + t.size());
	}
	
	/**
	 * Retrieves the description for the article at the specified index.
	 * @param index The index of the article to view.
	 * @return the description of the specified article.
	 */
	public String getDesc(int index) {
		return descs.get(index);
	}
	
	/**
	 * Retrieves the title for the article at the specified index.
	 * @param index The index of the article to view.
	 * @return the title of the specified article.
	 */
	public String getTitle(int index) {
		return titles.get(index);
	}
	
	/**
	 * Prints out all of the article data to System.out in the following format:
	 * [index#]Article Title\n
	 * [index#]Article Description
	 */
	public void printAll() {
		for(int i=0; i<size(); ++i) {
			System.out.println("[" + i + "]" + getTitle(i));
			System.out.println("[" + i + "]" + getDesc(i));
		}
	}
	
	/**
	 * Prints out all of the article data in an HTML string in the following format:
	 * <p>[index#]Article Title<br />
	 * <p>[index#]Article Description<br />
	 * @return an HTML-formatted string containing the RSSData's data.
	 */
	public String printAllHTML() {
		String s = "";
		for(int i=0; i<size(); ++i) {
			s = s + "[" + i + "]" + getTitle(i) + "<br />"
				+ "[" + i + "]" + getDesc(i) + "<br />";
		}
		return s;
	}
	
	/**
	 * Returns the number of RSS articles stored in this object.
	 * @return the number of articles stored.
	 */
	public int size() {
		return titles.size();
	}
}
